let reader = (data) => {
    // 获取表格dom
    let body = document.querySelector("tbody")
    body.innerHTML = ""
    for (let item of data) {
        let child = document.createElement("tr")
        child.innerHTML = `<td>${item.country}</td><td>${item.province}</td><td>${item.longitude},${item.latitude}</td><td>${item.totalAmount}</td><td>${item.modifyAmount}</td>`
        body.appendChild(child)
    }
}

let search = () => {
    let country = document.querySelector("input[name='country']").value
    let province = document.querySelector("input[name='province']").value
    let url = `/?country=${country}&province=${province}`
    axios.get(url)
        .then(({ data }) => {
            reader(data)
        })
        .catch(() => {
            alert("请求失败，请检查网络或稍后重试")
        })
}

let reset = () => {
    document.querySelector("input[name='country']").value = ""
    document.querySelector("input[name='province']").value = ""
}

window.onload = () => {
    document.querySelector("#search").addEventListener("click", search)
    document.querySelector("#reset").addEventListener("click", reset)

    search()
}